/**
 * 
 */
package com.vimeworks.vimemannager.web.converters;

import java.math.BigDecimal;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.vimeworks.vimemannager.ejb.aplicacion.TareasBeanLocal;
import com.vimeworks.vimemannager.ejb.exeptions.BusquedaException;
import com.vimeworks.vimemannager.ejb.exeptions.LocatorException;
import com.vimeworks.vimemannager.ejb.utilidades.ServiceLocator;
import com.vimeworks.vimemannager.modelo.aplicacion.Tarea;
import com.vimeworks.vimemannager.web.utilidades.Constantes;

/**
 * @author rsalazar
 *
 */

@FacesConverter(value = "com.vimeworks.vimemannager.web.converters.TareasConverter")
public class TareasConverter implements Converter {
	
    public Tarea getAsObject(FacesContext facesContext, UIComponent component, String s) {
        try {
        	TareasBeanLocal servicioTareas = (TareasBeanLocal)ServiceLocator.obtenerEJB(Constantes.NOMBRE_APLICACION + "/TareasBean/local");
			Tarea tarea = servicioTareas.buscarPorId(new BigDecimal(s));
			return tarea;
		} catch (NumberFormatException e) {
			return null;
		} catch (BusquedaException e) {
			return null;
		} catch (LocatorException e) {
			return null;
		}
    }
 
    public String getAsString(FacesContext facesContext, UIComponent component, Object o) {
    	Tarea tarea = (Tarea)o;
        return tarea.getCodigo().toString();
    }

}

